﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using WCrawlerLib;

namespace WCrawler
{
    public partial class frmTemplates : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //enable javascript
            //this.Page.Header.DataBind();

            if (!Page.IsPostBack)
            {
                dropDownListForumType.DataBind();
                dropDownListForumType.SelectedIndex = 0;
                gridViewTemplateDetails.DataBind();
            }
        }

        protected void dropDownListForumType_SelectedIndexChanged(object sender, EventArgs e)
        {
            ucTreeViewTemplate_SelectedIndexChanged(null, null);
        }

        protected void ucTreeViewTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            gridViewTemplateDetails.DataBind();
        }

        protected void TemplateDetailsLinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            if (!string.IsNullOrEmpty(dropDownListForumType.SelectedValue))
            {
                TemplateDetail objTemplateDetails = new TemplateDetail();
                if (ucTemplate.SelectedNode != null)
                {
                    if (ucTemplate.SelectedNode.Parent == null) //get all template of a forum type
                        e.Result = objTemplateDetails.GetTemplateDetailsByForumType(int.Parse(dropDownListForumType.SelectedValue));
                    else
                        e.Result = objTemplateDetails.GetTemplateDetails(int.Parse(dropDownListForumType.SelectedValue), int.Parse(ucTemplate.SelectedNode.Value));
                }
            }
        }

        protected void btnAddDetailsTemplate_Click(object sender, EventArgs e)
        {
            //TemplateDetail objTemplate = new TemplateDetail();
            //objTemplate.AddTemplateDetails(int.Parse(dropDownListForumType.SelectedValue), int.Parse(dropDownListTemplate.SelectedValue), txtTemplatePattern.Text, chkDefault.Checked);
            //gridViewTemplateDetails.DataBind();

            mdlPopup.Show();
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            TemplateDetail objTemplate = new TemplateDetail();
            objTemplate.AddTemplateDetails(int.Parse(dropDownListForumType.SelectedValue), int.Parse(ucTemplate.SelectedNode.Value), txtTemplatePattern.Text, chkDefault.Checked);
            gridViewTemplateDetails.DataBind();
        }
    }
}